#include "player.hpp"

#include "player_mgr.hpp"

PlayerMgr::PlayerMgr()
{
}

PlayerMgr::~PlayerMgr()
{
	PlayerMap_Iter iter = _player_map.begin(); 

	for (; iter != _player_map.begin(); ++ iter)
	{
		delete iter->second;
	}

	_player_map.clear();
}

Player * PlayerMgr::find_player(RID id)
{
	PlayerMap_Iter iter = _player_map.find(id);

	return ((_player_map.end() != iter)? iter->second: NULL);
}

Player * PlayerMgr::create_player(Connection & conn, const RoleB & role_b, const Position & position)
{
	Player * player = new Player(conn, role_b, position);
	
	if (NULL != player)
	{
		_player_map.insert(std::make_pair(player->id(), player));
	}

	return player;
}

